package com.xinhua.web.servlet;

import com.xinhua.util.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

//注册
@WebServlet("/registServlet")
public class RegistServlet extends HttpServlet {
    private QueryRunner queryRunner=new QueryRunner(JDBCUtils.getDataSource());
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password2 = req.getParameter("password");
        try {
            String sql="insert into day23.login values(null,?,?)";
            queryRunner.update(sql,username,password2);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        resp.sendRedirect(req.getContextPath()+"/index.jsp");

    }
}
